<?php
namespace app\common\respond;

/**
 * http api响应类
 */
class HttpApi
{
    /**
     * @Description 成功
     * @author: zj
     * @param array $data
     * @param string $msg
     * @param int $code
     * @time 2024/03/07 16:40:16
     * @return \think\response\Json
     */
    public function success (array $data, string $msg = '成功', int $code = 200) {
        return json ([
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        ]);
    }

    /**
     * @Description 失败
     * @author: zj
     * @param string $msg
     * @param int $code
     * @time 2024/03/07 16:40:03
     * @return \think\response\Json
     */
    public function error (string $msg, int $code = 400) {
        return json ([
            'code' => $code,
            'msg' => $msg
        ]);
    }

}